var domType = "";
var returnObj = null;
var opObj = null;
var http_request = false;
var tempObj = null;
var op = "";
var mouse_x = 0, mouse_y = 0;
var wait = 200;
var pathtemp = "";
var syn = true;
var loading='<div class="load"><div class="load_left"></div><div class="load_mid">载入中...</div><div class="load_right"></div></div>';
if (document.all) {
    domType = "ie4";
} else {
    if (document.getElementById) {
        domType = "std";
    } else {
        if (document.layers) {
            domType = "ns4";
        }
    }
}
function myuri(str)
{
	str=encodeURI(str);
	str=str.replace(/\+/g,"%2B");
	str=str.replace(/&/g,"%26");
	str=str.replace(/%5C/g,"\\");
	str=str.replace(/#/g,"%23");
	return str;
}
function send_request(url) {
    tempurl = url;
    http_request = false;
    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType("text/xml");
        }
    } else {
        if (window.ActiveXObject) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                    syn = true;
                }
                catch (e) {
                }
            }
        }
    }
    if (!http_request) {
        window.alert("");
        return false;
    }
    http_request.onreadystatechange = processRequest;
    http_request.open("GET",url, syn);
    http_request.send(null);
}
function processRequest() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            try {
                returnObj = http_request.responseXML;
                AjaxOperation();
            }
            catch (e) {
            }
        } else {
            alert("");
        }
    }
}
function addNode(nodes) {
    outprint = "";
    if (nodes.length == 0) {
        outprint = "<span class='none'>    [NONE]</span>";
    }
    for (i = 0; i < nodes.length; i++) {
        id = nodes[i].getAttribute("id");
        name = nodes[i].getAttribute("name");
        path = nodes[i].getAttribute("path");
        outprint += "<div class=\"items\" onclick=\"selected(this)\"><img src=\"images/close.gif\" id=\"OC_" + id + "\" onclick=\"OCclick('" + path + "','" + id.replace(/'/g,"\\'") + "',this)\" /><img src=\"images/folder.png\" onclick=\"icoClick(this,'" + id.replace(/'/g,"\\'") + "','" + path + "')\" /><a href=\"javascript:nameClick(this,'" + id.replace(/'/g,"\\'") + "','" + path + "')\" class=\"filename\" id=\"N_" + id + "\">" + name + "</a></div><div id=\"" + id + "\" class=\"folderlist\" style=\"display:none\"></div>";
    }
    return outprint;
}
function AjaxOperation() {
    switch (op) {
      case "doChange":
        var nodes = returnObj.getElementsByTagName("main")[0].getElementsByTagName("file");
        var main = "";
        main += addNode(nodes);
        tempObj.innerHTML = main;
        break;
      case "info":
        var node = returnObj.getElementsByTagName("main")[0].getElementsByTagName("file")[0];
        id = node.getAttribute("id");
        fname = node.getAttribute("name");
        tpath = node.getAttribute("path");
        pic = node.getAttribute("pic");
        FsDs = node.getAttribute("FsDs");
        ext = node.getAttribute("ext");
        size = node.getAttribute("size");
        last = node.getAttribute("last");
        tsize = node.getAttribute("tsize");
		o = document.getElementById("maininfo");
        o.innerHTML = "<div style='width:100%;height:50px;background:#fff;'><img style='float:left' src=\"" + pic + "\" /></div>";
        o.innerHTML+= "<a style='float:right' href='FeedServlet?path="+myuri(tpath)+"'><img src='images/rss2.png' style='border:1px #99F solid' title='RSS订阅当前文件夹' onmousemove='altMouseMove(this)' onmouseout='altMouseOut(this)'/></a>";
        o.innerHTML +='<div style="border-bottom:1px #99f solid;height:2px;background:#FFF">'
        o.innerHTML += addProItem("名称",fname);
        o.innerHTML += addProItem("路径",tpath);
        o.innerHTML += addProItem("类型",ext);
		o.innerHTML += addProItem("日期",last);
		o.innerHTML += "<div style='color:#EEE;background:#777;border:#AAF solid 1px;width:85px;float:right;'>以下为索引信息</div><hr style='color:#AAF''/>";
		o.innerHTML += addProItem("大小",tsize);
		if(FsDs!='') o.innerHTML += addProItem("信息",FsDs);
		
    }
}
function addProItem(name,value)
{
	return "<div class='proitem'><div><strong>"+name+"</strong></div><div>"+value+"</div></div>";
}
function doChange(obj, path) {
    op = "doChange";
    tempObj = obj;
    tempObj.style.display = "";
    tempObj.innerHTML="   loading..."
    send_request("Listfiles?dironly=1&" + "path=" + myuri(path));
}
function winEffect(node,x,y,w,h)
{
	_w=0;_h=0;
	node = document.getElementById(node);
effect = setInterval(function () {
	xspd = (w-_w)/3+1;
	yspd = (h-_h)/3+1;
	if(_w<w) _w+=xspd;
	if(_h<h) _h+=yspd;
	node.style.left = x - _w/2 +"px";
	node.style.top = y- _h/2+"px";
	if(_w>=w && _h>h)     
		clearInterval(effect);
	node.style.height = _h +"px";
	node.style.width = _w+"px";
	},15)
}

function viewInfo(path) {
    op = "info";
        inner = '<div id="pro" class="windows" style="left:'+mouse_x+'px;top:'+mouse_y+'px;">';
    inner+=	'	<div class="window_head" onmousedown=MouseDown(this) onmousemove=MouseMove() onmouseup=MouseUp()>';
    inner+='		<div class="window_head_left"></div>';
    inner+='		<div class="window_head_mid"></div>';
    inner+='		<div class="window_head_right"></div>';
    inner+='		<div onclick="infoClose()" class="window_close"></div>';
    inner+='	</div>' ;
    inner+='	<div class="infobody"><div id="maininfo"></div></div>' ;
    inner+='</div>';
    obj=document.getElementById("info").innerHTML=inner;
	winEffect('pro',mouse_x+150,mouse_y+160,300,320);
	document.getElementById("maininfo").innerHTML=loading;
    send_request("getProperties?path=" + myuri(path));
}

function infoClose()
{
	obj=document.getElementById("pro");
	document.getElementById('info').innerHTML='';
}
function initMouseMove() {
    if (!document.all) {
        document.captureEvents(Event.MOUSEMOVE);
    }
    document.onmousemove = mouseMove;
}
function mouseMove(e) {
    var x, y;
    if (!document.all) {
        x = e.pageX;
        y = e.pageY;
    } else {
        x = document.body.parentNode.scrollLeft + event.clientX;
        y = document.body.parentNode.scrollTop + event.clientY;
    }
    mouse_x = x;
    mouse_y = y;
}
var objects = new Array();
function fetch_object(idname, forcefetch) {
    if (forcefetch || typeof (objects[idname]) == "undefined") {
        switch (domType) {
          case "std":
            objects[idname] = document.getElementById(idname);
            break;
          case "ie4":
            objects[idname] = document.all[idname];
            break;
          case "ns4":
            objects[idname] = document.layers[idname];
            break;
        }
    }
    return objects[idname];
}
function menuonload(thisnode) {
    thisnode.style.left = mouse_x - 16;
    thisnode.style.top = mouse_y - 16;
}
var timer = 0;
var mouseUp = true;
var my = null;
var moved = false;
function menuMouseDown(path, type) {
    pathtemp = path;
    timer = 0;
    moved = false;
    mouseUp = false;
    var tempElement = document.getElementById("poptemp");
    my = setInterval(function () {
        timer += 50;
        if (!mouseUp && !moved) {
            if (timer >= wait && timer < wait + 30) {
                tempElement.innerHTML = "<div id=\"pop\" style=\"width:32px;height:32px;background:url(images/menupop.gif);position:absolute;left:" + (mouse_x - 16) + "px;top:" + (mouse_y - 16) + "px\"/>";
                tempElement = tempElement.firstChild;
            } else {
                for (i = 1; i <= 8; i++) {
                    if (timer >= (wait + i * 30) && timer <= ((i + 1) * 30) + wait) {
                        tempElement.style.backgroundPosition = "0% " + 32 * (9 - i) + "px";
                        break;
                    }
                }
            }
            if (timer > wait + 9 * 30) {
                initMenu();
                viewInfo(path);
            }
        } else {
            initMenu();
        }
    }, 50);
}
function initMenu() {
    moved = false;
    document.getElementById("poptemp").innerHTML = "";
	try
	{
    clearInterval(my);
	}catch(e){}
}
function menuMouseUp() {
	initMenu();
    mouseUp = true;

}
function menuMouseMove() {
    moved = true;
}
function find(path, leftDOM) {
	if(parent.document.getElementById("leftset").cols=="0,*") return;
    if (domType == "ie4") {
        syn = false;
    }
    var tempid = "id_|";
    if (leftDOM.getElementById("left").innerHTML == "") {
        doChange(leftDOM.getElementById("left"), "\\");
        leftDOM.getElementById("OC_left").src = "images/open.gif";
    }
    var f_array = path.split("\\");
    for (i = 1; i < f_array.length - 1; i++) {
        tempid = "id_|";
        tpath = "\\";
        for (j = 1; j < i + 1; j++) {
            if (f_array[j] != "") {
                tempid += f_array[j] + "|";
                tpath += f_array[j] + "\\";
            }
        }
        try {
            if (leftDOM.getElementById(tempid).innerHTML == "") {
                doChange(leftDOM.getElementById(tempid), tpath);
                leftDOM.getElementById("OC_" + tempid).src = "images/open.gif";
            }
        }
        catch (NullPointerException) {
        }
    }
    alist = leftDOM.getElementsByTagName("a");
    for (var i = 0; i < alist.length; i++) {
        alist[i].style.background = "";
    }
    leftDOM.getElementById("N_" + tempid).style.background = "#c5e7f6";
    syn = true;
}
var titletemp="";
function altMouseMove(thisnode)
{
	try{
		obj=document.getElementById('alt');
		obj.style.left  = mouse_x+10+ "px";
        obj.style.top  = mouse_y+10+ "px";
		}
		catch(e)
		{
			titletemp=thisnode.title;
			document.getElementById("alttemp").innerHTML='<div id="alt" style="left:0px;top:-50px">'+titletemp+'</div>';
			thisnode.title="";
		}

}
function altMouseOut(thisnode)
{
	thisnode.title=titletemp;
	document.getElementById('alttemp').innerHTML='';
}